from playwright.sync_api import Playwright, sync_playwright
import getpass

user_data_dir = fr'C:\Users\{getpass.getuser()}\AppData\Local\Google\Chrome\User Data'


def run(playwright: Playwright) -> None:
    context = playwright.chromium.launch_persistent_context(
        # 本地浏览器的数据目录
        user_data_dir=user_data_dir,
        # 指定Google
        channel='chrome',
        # 无头模式
        headless=False
    )
    page = context.new_page()
    page.goto("https://www.baidu.com/")

    page.pause()
    # ---------------------
    context.close()


with sync_playwright() as playwright:
    run(playwright)
